auto.waitFor();
var widthG = device.width;
var myFunc = require("./myCommonFunction.js");
var ret = myFunc.initNetWork(null, true);
var app = [ '京东', '智取1', '智取2', '智取J']


opreation()
function opreation() {
    for (let appName of app) {
        try {
            dotask(appName)
        } catch (error) {
            log(error)
            myFunc.tuichuAll()
            dotask(appName)  
        }
        
    }
    
}
function dotask(appName) {
    log(appName)
    myFunc.openMyApp(appName);
    myFunc.findOne('搜索', 5000)
    sleep(1000)
    click(310, 300)
    sleep(2000)
    while(myFunc.findOne('搜索历史') == null) {
        myFunc.openMyApp(appName);
        myFunc.tuichuToStr('东东农场')
        sleep(2000)
        click(310, 300)
        sleep(2000)
    }
    if(!myFunc.clickByText('有奖答题')) {
        input('有奖答题')
        sleep(1000)
        myFunc.clickByText('搜素')
    }
    myFunc.findOne('已获得京豆', 10000)
    sleep(2000)
    var task = textMatches(".*赢\\d+.*京豆.*").findOne(3000);
    if(task == null) {
        myFunc.log('没有找到领豆任务')
        myFunc.tuichu(appName)
        return;
    }
    click(widthG/2, task.bounds().top - 100)
    sleep(2000)
    myFunc.clickByText('立即参与', 10000)
    sleep(2000)
    while(myFunc.findOne('下一页') != null){
        var a = className("android.widget.CheckBox").findOnce();
        if(a == null) {
            a = className('android.widget.RadioButton').findOnce();
        }
        a.click()
        sleep(500)
        myFunc.clickByText('下一页')
        sleep(1000)
    }
    if(myFunc.findOne('提交') != null){
        var a = className("android.widget.EditText").findOnce();
        if(a == null) {
            a = className('android.widget.RadioButton').findOnce();
            a.click()
        } else {
            input(" ")
        }
        sleep(500)
        myFunc.clickByText('提交')
        sleep(1000)
    }
    myFunc.tuichu(appName)
}